#include<vector>
using namespace std;

int dx[4] = { 0, 0, 1, -1 };
int dy[4] = { 1, -1, 0, 0 };
int m, n;
void dfs1(vector<vector<char>>& board, int i, int j)
{
    for (int k = 0; k < 4; k++)
    {
        int x = i + dx[k], y = j + dy[k];
        if (x >= 0 && x < m && y >= 0 && y < n && board[x][y] == 'O')
        {
            board[x][y] = '.';
            dfs1(board, x, y);
        }
    }
}
void dfs2(vector<vector<char>>& board, int i, int j)
{
    for (int k = 0; k < 4; k++)
    {
        int x = i + dx[k], y = j + dy[k];
        if (x >= 0 && x < m && y >= 0 && y < n && board[x][y] == 'O')
        {
            board[x][y] = 'X';
            dfs2(board, x, y);
        }
    }
}
void solve(vector<vector<char>>& board) {
    m = board.size(), n = board[0].size();
    for (int i = 0; i < m; i++)
    {
        if (board[i][0] == 'O')
        {
            board[i][0] = '.';
            dfs1(board, i, 0);
        }
        if (board[i][n - 1] == 'O')
        {
            board[i][n - 1] = '.';
            dfs1(board, i, n - 1);
        }
    }
    for (int j = 0; j < n; j++)
    {
        if (board[0][j] == 'O')
        {
            board[0][j] = '.';
            dfs1(board, 0, j);
        }
        if (board[m - 1][j] == 'O')
        {
            board[m - 1][j] = '.';
            dfs1(board, m - 1, j);
        }
    }
    for (int i = 1; i < m - 1; i++)
    {
        for (int j = 1; j < n - 1; j++)
        {
            if (board[i][j] == 'O')
            {
                board[i][j] = 'X';
                dfs2(board, i, j);
            }
        }
    }
    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (board[i][j] == '.') board[i][j] = 'O';
        }
    }
}

int main()
{
    
    vector<vector<char>> vv{ {'X','X','X','X'} ,{'X','O','O','X'},{'X','X','O','X'},{'X','O','X','X'} };
    solve(vv);

	return 0;
}